package Drink

object Drink {
  def main(args: Array[String]): Unit = {
    println(s"一共喝了${drink(100)}瓶啤酒")
  }


  def drink(money:Int):Int={
    val buy = money/2

    val exchangeBear = exchange(buy)

    println(s"换取了${exchangeBear}瓶啤酒")

    buy+exchangeBear
  }


  var cap = 0
  var bottle = 0
  var totalExchange = 0

  def exchange(buy:Int):Int={
    cap += buy
    bottle +=buy

    var capToBear =0
    var bottleToBear =0

    if(cap<5 && bottle<3)  return 0


    if(cap>=5){
      capToBear = cap/5
      cap = cap%5
    }


    if(bottle>=3){
      bottleToBear = bottle/3
      bottle = bottle%3
    }

    totalExchange = capToBear+bottleToBear
    totalExchange+exchange(totalExchange)

  }
}
